package com.litq.education.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.litq.education.service.CustomerService;
import com.litq.education.service.VipService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * VipController
 *
 * @author Litq
 * @version v1.0
 * @since 2019/2/10 1:30
 */
@RestController
public class VipController {

    Logger logger = LoggerFactory.getLogger(CustomerController.class);

    @Resource
    private VipService VipService;

    @ResponseBody
    @RequestMapping(value = "/VipqueryAll", method = {RequestMethod.POST, RequestMethod.GET})
    public Object queryAll(@RequestBody(required = false) Map<String, Object> reqMap) {

        logger.info("查询信息打印----------------------------------开始查询");
        logger.info("查询信息打印----------------------------------是否有参数:" + reqMap);

        //current 第几页   number 一页多少条
        Map<String, Object> map = new HashMap<String, Object>();

        if (null == reqMap.get("username") || "".equals(reqMap.get("username"))) {
            int pageCount = Integer.parseInt(reqMap.get("page").toString());
            int limit = Integer.parseInt(reqMap.get("limit").toString());
            int count = VipService.selectListcount();
            logger.info("查询信息打印----------------------------------数据总条数:" + count);
            Page<Map<String, Object>> page = VipService.selectListPage(pageCount, limit);
            List list = page.getRecords();
            map.put("code", 0);
            map.put("msg", "用户数据表");
            map.put("count", count);
            map.put("data", list);
            return map;
        } else {
            String username = reqMap.get("username").toString();
            logger.info("查询信息打印----------------------------------参数" + username);
            List list = (List) VipService.selectListPageByUserName(username);
            map.put("code", 0);
            map.put("msg", "用户数据表");
            map.put("count", list.size());
            map.put("data", list);
            return map;
        }
    }

    /**
     * @Method 根据id删除客户信息
     * @Author Litq
     * @Version 1.0
     * @Description 根据id删除客户信息
     * @since 2019/8/15
     */

    @ResponseBody
    @RequestMapping(value = "/vipdeleteById", method = {RequestMethod.POST, RequestMethod.GET})
    public int deleteById(@RequestBody(required = false) Map<String, Object> reqMap) {
        logger.info("删除信息打印----------------------------------开始删除");
        logger.info("删除信息打印----------------------------------是否有参数:" + reqMap);

        int id = Integer.parseInt(reqMap.get("id").toString());

        logger.info("查询信息打印----------------------------------是否有参数:" + id);
        int sign = VipService.deleteById(id);
        return sign;
    }


    /**
     * @Method 根据id查询客户信息
     * @Author Litq
     * @Version 1.0
     * @Description 根据id查询客户信息
     * @since 2019/8/15
     */
    @ResponseBody
    @RequestMapping(value = "/findVipById", method = {RequestMethod.POST, RequestMethod.GET})
    public Map findCustomerById(@RequestBody(required = false) Map<String, Object> reqMap) {
        logger.info("查询信息打印----------------------------------开始查询");
        logger.info("查询信息打印----------------------------------是否有参数:" + reqMap);

        int id = Integer.parseInt(reqMap.get("id").toString());

        logger.info("查询信息打印----------------------------------是否有参数:" + id);
        Map map = VipService.findCustomerById(id);
        return map;
    }

    /**
     * @Method 根据id修改客户信息
     * @Author Litq
     * @Version 1.0
     * @Description 根据id修改客户信息
     * @since 2019/8/15
     */
    @ResponseBody
    @RequestMapping(value = "/updateVipById", method = {RequestMethod.POST, RequestMethod.GET})
    public int updateCustomerById(@RequestBody(required = false) Map<String, Object> reqMap){
        logger.info("修改信息打印----------------------------------开始修改");
        logger.info("修改信息打印----------------------------------是否有参数:" + reqMap);

        int sign = VipService.updateCustomerById(reqMap);
        logger.info("修改信息打印----------------------------------修改结果:" + sign);
        return sign;
    }

    /**
     * @Method 插入一条记录
     * @Author Litq
     * @Version 1.0
     * @Description 插入一条记录
     * @since 2019/8/15
     */
    @ResponseBody
    @RequestMapping(value = "/insertVip", method = {RequestMethod.POST, RequestMethod.GET})
    public int insertCustomer(@RequestBody(required = false) Map<String, Object> reqMap){
        logger.info("插入信息打印----------------------------------开始插入");
        logger.info("插入信息打印----------------------------------是否有参数:" + reqMap);

        int sign = VipService.insertCustomer(reqMap);
        logger.info("修改信息打印----------------------------------修改结果:" + sign);
        return sign;
    }

}
